if (WIN32)
    cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
else()
    cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
endif()

if(NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE Release
		CACHE STRING "Set build type to Debug or Release (default Release)" FORCE)
endif()

string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)

set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "Limited configurations" FORCE)

project (libredis-parser C)

set(SOURCE_FILES_DIR ${PROJECT_SOURCE_DIR}/src)
set(TEST_FILES_DIR ${PROJECT_SOURCE_DIR}/test)

if(WIN32)
    set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
    set(CMAKE_REQUIRED_LIBRARIES  ws2_32.lib)
    set(CMAKE_REQUIRED_DEFINITIONS -FIwinsock2.h -FIws2tcpip.h)
	set(LIB_PLATFORM ws2_32)
    add_definitions(
            -D_CRT_SECURE_NO_WARNINGS
            -D_CRT_NONSTDC_NO_DEPRECATE)
else()
	set(LIB_PLATFORM)
endif()

include_directories(BEFORE ${SOURCE_FILES_DIR})

set(SOURCE_FILES
	${SOURCE_FILES_DIR}/redis_parser.c)

set(HEADER_FILES 
	${SOURCE_FILES_DIR}/redis_parser.h)

source_group("HEADERS" FILES ${HEADER_FILES})
source_group("SOURCES" FILES ${SOURCE_FILES})

add_library(redis-parser STATIC ${HEADER_FILES} ${SOURCE_FILES})

set(PLATFORM_LIB)

add_executable(test-reply 
	${TEST_FILES_DIR}/utility.h
	${TEST_FILES_DIR}/utility.c
	${TEST_FILES_DIR}/test_reply.c)
target_link_libraries (test-reply redis-parser ${PLATFORM_LIB})

add_executable(test-request
	${TEST_FILES_DIR}/utility.h
	${TEST_FILES_DIR}/utility.c
	${TEST_FILES_DIR}/test_request.c)
target_link_libraries (test-request redis-parser ${PLATFORM_LIB})